﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using log4net;

namespace app2
{
    class Database
    {
        private static ILog _log = LogManager.GetLogger(typeof(Database));
        public OleDbConnection dataConnection = new OleDbConnection();
        public OleDbDataAdapter dataadapter = new OleDbDataAdapter();
        public DataSet dataset = new DataSet();
        public OleDbCommand command = new OleDbCommand();

        //定义连接字符串
        string connstr = @"Provider = Microsoft.Jet.OLEDB.4.0;" + @"Data Source =.\CrazyBoll.mdb";
        public DataSet GetDataFromDB(string sqlStr)
        {
            try
            {
                dataConnection.ConnectionString = connstr;
                dataadapter = new OleDbDataAdapter(sqlStr, dataConnection);
                dataset.Clear();
                dataadapter.Fill(dataset);
                dataConnection.Close();

                
            }

            catch (Exception ex)
            {
                _log.Error(ex.Message);
                MessageBox.Show(ex.Message);
                dataConnection.Close();
            }
           
                return dataset;
            　
               
        }
        public bool UpdataDB(string sqlStr)
        {
            try
            {
                dataConnection.ConnectionString = connstr;
                dataConnection.Open();
                command = dataConnection.CreateCommand();
                command.CommandText = sqlStr;
                command.ExecuteNonQuery();
                dataConnection.Close();
                return true;

            }
            catch (Exception x)
            {
                _log.Error(x.Message);
                MessageBox.Show(x.Message);
                dataConnection.Close();
                return false;
            }
        }       
    }
}
